using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/****************************************************
// 功能：辅助逻辑单位
// | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
// | Copyright (c) 2021-2025 聊来 All rights reserved.
// | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">聊来</a> )
// | @Author: 贯彻己道的云 <18970881148@qq.com>
// | DateTime: 2025/4/8 16:42:57
*****************************************************/

public abstract class SubLogicUnit : LogicUnit
{
    // 辅助单元来源角色
    public MainLogicUnit source;
    protected Skill skill;

    // 延迟生效时间
    protected int delayTime;
    // 延迟时间计数
    protected int delayCounter;
    // 辅助单元的状态
    public SubUnitState unitState;
    
    protected SubLogicUnit(MainLogicUnit source, Skill skill)
    {
        this.source = source;
        this.skill = skill;
    }
    
    public override void LogicInit()
    {
        if(delayTime == 0) {
            unitState = SubUnitState.Start;
        }
        else {
            delayCounter = delayTime;
            unitState = SubUnitState.Delay;
        }
    }

    public override void LogicTick()
    {
        switch(unitState) {
            case SubUnitState.Delay:
                delayCounter -= Constants.SERVER_LOGIC_FRAME_ID;
                if(delayCounter <= 0) {
                    unitState = SubUnitState.Start;
                }
                break;
            case SubUnitState.End:
                End();
                unitState = SubUnitState.None;
                break;
            case SubUnitState.None:
            case SubUnitState.Start:
            case SubUnitState.Tick:
            default:
                break;
        }
    }

    public override void LogicUnInit() {}
    
    protected abstract void Start();
    protected abstract void Tick();
    protected abstract void End();
}

public enum SubUnitState
{
    None,
    Delay,
    Start,
    Tick,
    End
}
